package AccountWindow.SystemAdmin;

import AccountWindow.SystemAdmin.AccountDetailWindow.AccountDetailWindow;
import AccountWindow.SystemAdmin.NewRegisterWindow.NewRegisterWindow;
//import AccountWindow.SystemAdmin.ReserveDetailWindow.ReserveDetailWindow;
import AccountWindow.SystemAdmin.RoomDetailWindow.RoomDetailWindow;

import javax.swing.*;
import java.awt.*;

public class SystemAdminWindow extends JFrame{

    public static String nowAccountID;

    public JPanel systemAdminPanel;
    public CardLayout cardLayout = new CardLayout();

    private JMenuBar menuBar = new JMenuBar();
    //客房信息、用户信息、新增批准、个人信息
    private JButton roomDetail = new JButton("客房信息");
    private JButton accountDetail = new JButton("用户信息");
//    private JButton reserveDetail = new JButton("订单信息");
    private JButton newRegister = new JButton("新增批准");
    private JButton personalDetail = new JButton("个人信息");

    public RoomDetailWindow roomDetailWindow;    //其实这些Window都是JPanel的子类，笔者为了将后继功能抽离出去，故另设新类，各Window当JPanel用就行
    public AccountDetailWindow accountDetailWindow;
    public NewRegisterWindow newRegisterWindow;
    public PersonalDetailWindow personalDetailWindow;

    private SystemAdminWindowHandler systemAdminWindowHandler = new SystemAdminWindowHandler(this);

    public SystemAdminWindow(String accountID){

        this.nowAccountID = accountID;

        roomDetailWindow = new RoomDetailWindow(nowAccountID);
        accountDetailWindow = new AccountDetailWindow(nowAccountID);
//        reserveDetailWindow = new ReserveDetailWindow(nowAccountID);
        newRegisterWindow = new NewRegisterWindow(nowAccountID);
        personalDetailWindow = new PersonalDetailWindow(nowAccountID);

        systemAdminPanel = new JPanel();
        this.add(systemAdminPanel);
        systemAdminPanel.setLayout(cardLayout);
        placeComponents(systemAdminPanel);

        roomDetail.setActionCommand("roomDetail");
        roomDetail.addActionListener(systemAdminWindowHandler);
        accountDetail.setActionCommand("accountDetail");
        accountDetail.addActionListener(systemAdminWindowHandler);
//        reserveDetail.setActionCommand("reserveDetail");
//        reserveDetail.addActionListener(systemAdminWindowHandler);
        newRegister.setActionCommand("newRegister");
        newRegister.addActionListener(systemAdminWindowHandler);
        personalDetail.setActionCommand("personalDetail");
        personalDetail.addActionListener(systemAdminWindowHandler);


        this.setBackground(Color.white);
        setTitle("系统管理员界面");
        setBounds(0, 0, 800, 530);
        setLocationRelativeTo(null);//居中显示
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);  //用户单击窗口的关闭按钮时程序执行的操作
        setResizable(true);
        setVisible(true);

    }

    private void placeComponents(JPanel systemAdminPanel){

        menuBar.add(roomDetail);
        menuBar.add(accountDetail);
//        menuBar.add(reserveDetail);
        menuBar.add(newRegister);
        menuBar.add(personalDetail);

        //默认系统管理员一打开见到的就是roomDetailWindow，先从数据库中拉取数据填充roomDetailWindow的内容，后将roomDetailWindow以卡片布局的形式显现出来
        //下列添加的顺序颇为重要，First Add First Appear
        systemAdminPanel.add(roomDetailWindow,"roomDetailPanel");
        systemAdminPanel.add(accountDetailWindow,"accountDetailPanel");
//        systemAdminPanel.add(reserveDetailWindow,"reserveDetailPanel");
        systemAdminPanel.add(newRegisterWindow,"newRegisterPanel");
        systemAdminPanel.add(personalDetailWindow,"personalDetailPanel");

        this.setJMenuBar(menuBar);

    }

}
